package cn.stronglink.assetmanage.business.task.view.wait;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.task.adapter.TaskListAdapter;
import cn.stronglink.assetmanage.business.task.model.TaskWaitModel;
import cn.stronglink.assetmanage.business.task.presenter.TaskWaitPresenter;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;
import cn.stronglink.assetmanage.widget.ViewPagerFragment;

/**
 *待处理任务
 */
public class TaskWaitFragment extends ViewPagerFragment {
    private LinearLayoutManager layoutManager;
    private RecyclerView rv_taskwait_order_list;
    private TaskListAdapter listAdapter;
    private TaskWaitModel taskWaitModel;
    private TaskWaitView taskWaitView;
    private TaskWaitPresenter taskWaitPresenter;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_task_wait,container,false);
        initViewAndData(rootView);
        return rootView;
    }

    private void initViewAndData(View view) {
        rv_taskwait_order_list = view.findViewById(R.id.rv_taskwait_order_list);
        listAdapter = new TaskListAdapter(getActivity());
        layoutManager = new LinearLayoutManager(getActivity());
        rv_taskwait_order_list.setLayoutManager(layoutManager);
        rv_taskwait_order_list.setAdapter(listAdapter);
        listAdapter.setOnItemClickListener(new onRecyclerListener() {
            @Override
            public void onItemClicked(View v, int postion) {
                taskWaitView.showTaskAssetFragment(postion);
            }
        });
        taskWaitModel = new TaskWaitModel();
        taskWaitView = new TaskWaitView(this,view,listAdapter);
        taskWaitPresenter = new TaskWaitPresenter(taskWaitModel,taskWaitView);
        taskWaitPresenter.initWaitTaskData();
    }

    @Override
    protected void onFragmentVisibleChange(boolean isVisible) {
        try{
            if(isVisible && taskWaitPresenter!=null){
                taskWaitPresenter.initWaitTaskData();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

}
